package com.mmall.pay.service.impl;

import com.mmall.common.enums.BooleanEnum;
import com.mmall.pay.enums.FlowStateEnum;
import com.mmall.pay.enums.OptionTypeEnum;
import com.mmall.pay.mapper.PaymentFlowMapper;
import com.mmall.pay.pojo.entity.PaymentFlowEntity;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author gg
 * @version PaymentFlowService.java, v 0.1 2019-05-31 16:30 gg
 */
@Service("paymentFlowService")
public class PaymentFlowService {

    @Resource
    private PaymentFlowMapper paymentFlowMapper;

    public void addFlow(String openId, String outTradeNo, Long memberId, String memberName, Integer platFormType, Integer type, OptionTypeEnum refund, Long publicId, Integer totalFee) {
        PaymentFlowEntity paymentFlowEntity = new PaymentFlowEntity();
        paymentFlowEntity.setOutTradeNo(outTradeNo);
        paymentFlowEntity.setMemberId(memberId);
        paymentFlowEntity.setMemberName(memberName);
        paymentFlowEntity.setNotified(BooleanEnum.FALSE.getValue());
        paymentFlowEntity.setOpenId(openId);
        paymentFlowEntity.setPlatFormType(platFormType);
        paymentFlowEntity.setType(type);
        paymentFlowEntity.setOptionType(refund.getCode());
        paymentFlowEntity.setPublicId(publicId);
        paymentFlowEntity.setState(FlowStateEnum.NOT_AUDIT.getCode());
        paymentFlowEntity.setTotalFee(totalFee);
        paymentFlowMapper.insertSelective(paymentFlowEntity);
    }


    public void updateFlow(PaymentFlowEntity paymentFlowEntity){
        paymentFlowMapper.updateByOutTradeNoAndOptionType(paymentFlowEntity);
    }
}